//
// Created by 谢哲 on 2021/4/19.
//

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;

    vector<pair<int, string>> vdata;

    for (int i=0;i<n;++i) {
        int a;
        string s;
        cin >> a >> s;
        vdata.emplace_back(make_pair(a, s));
    }

    int cur = 0;
    for (;m;--m) {
        int a, b;
        cin >> a >> b;
        if (a==vdata[cur].first) {
            cur = (cur+n-b) % n;
        }
        else {
            cur = (cur+b) % n;
        }
    }

    cout << vdata[cur].second;

    return 0;
}